﻿Ext.define('app.prm.task.edit.Attachment', {
    extend: 'Ext.grid.Panel',
    taskId: 0,
    tbar: [],
    border: false,
    autoHeight: true,
    viewConfig: {
        forceFit: true
    },
    initComponent: function () {
        var me = this;
        me.store = Ext.create("app.ux.PrmStore", { url: '/api/services/app/gantt/GetFiles?taskId=' + me.taskId });
        me.tbar = ["->", { text: '新增一行', icon: '/Content/images/add.png', handler: function () { me.getWin().show(); } }];
        me.callParent();
    },
    columns:[
        {
            header: '名称',
            dataIndex: 'name'
        },
        {
            header: '类型',
            dataIndex: 'extension'
        },
        {
            header: '创建人',
            dataIndex: 'createBy'
        },
        {
            header: '创建时间',
            dataIndex: 'createOn'
        }
        //{
        //    xtype: "actioncolumn",
        //    header: "下载",
        //    width: 70,
        //    items: [
        //    {
        //        icon: '/Content/images/download.gif',
        //        tooltip: "下载",
        //        handler: function (grid, rindex, cindex) {
        //            var record = grid.store.getAt(rindex);
        //            window.location.href = "/Project/Gantt/Download?attId=" + record.data.Id;
        //        }
        //    }]
        //}
    ],
    getWin: function () {
        var me = this;
        if (!this.winPanel) {
            this.winPanel = new Ext.Window({
                title: '上传文档',
                modal: true,
                width: 450,
                closable: false,
                height: 300,
                layout: 'fit',
                bodyStyle: 'padding:2px',
                items: [me.getFormPanel()],
                buttons: [
                    { text: '保存', handler: function () { me.saveForm(); } },
                    { text: '关闭', handler: function () { me.closeWin(); } }
                ]
            });
        }
        return this.winPanel;
    },
    closeWin: function ()
    {
        this.getWin().hide();
    },
    saveForm: function () {
        var me = this;
        me.getFormPanel().getForm().submit(
        {
            url: '/api/services/app/gantt/SaveAttachment',
            params: { TaskId: me.taskId },
            success: function (form, action) {
                me.getStore().load();
                me.getWin().close();
            }
        });
    },
    getFormPanel: function () {
        if (!this.formpanel) {
            this.formpanel = new Ext.form.FormPanel({
                fileUpload: true,
                labelAlign: 'right',
                labelWidth: 80,
                frame: true,
                defaults: { width: '85%' },
                bodyStyle: 'padding:50px 0 0 0',
                items: [
                    {
                        xtype: 'fileuploadfield',
                        allowBlank: false,
                        emptyText: '选择文件',
                        fieldLabel: '文件',
                        name: 'file',
                        buttonText: '浏览'
                    }
                ]
            });
        }
        return this.formpanel;
    }
});
